#include "Classes.h"

File::File(const char* FilePath) {
	Path = FilePath;
}
int File::Copy(std::string Source_File_Path, std::string Dest_File_Path) {
	// setup IO streams for binary mode file copy
	ifstream source(Source_File_Path.c_str(),ios::binary);
	ofstream dest(Dest_File_Path.c_str(),ios::binary);

	// perform file copy operation
	dest << source.rdbuf();

	// verify operation
	if(!dest) {
		perror("Error copying file\n");
		return -1;
	} else {
		puts("File copy was successful\n");
		return 0;
	}
}
int File::Delete(std::string File_Path) {
	if(remove(File_Path.c_str()) != 0) {
		perror("Error deleting file\n");
		return -1;
	} else {
		puts("File successfully deleted\n");
		return 0;
	}
}
xml_document* File::GetXML() {
	return &XML;
}
bool File::Read() {
	xml_parse_result result = XML.load_file(Path);
	if(result) {
		return true;
	} else {
		return false;
	}
}
int File::Rename(std::string Source_File_Path, std::string Dest_File_Path) {
	if(Copy(Source_File_Path,Dest_File_Path) == 0) {
		if(Delete(Source_File_Path) == 0) {
			return 0;
		} else {
			goto end;
		}
	} else {
		goto end;
	}
	end:
	return -1;
}